package edu.neu.cs6515.gui;

import java.util.*;
import javax.swing.table.*;
import javax.swing.*;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.table.JTableHeader;

import edu.neu.cs6515.xml.IngeniousColor;
import edu.neu.cs6515.xml.Score;

/**
 * to render score
 */
public class ScoreRenderer extends JPanel {

    private static final long serialVersionUID = 1L;

    /**
     * C'tor
     * 
     */
    public ScoreRenderer() {
        super();
        this.setBorder(BorderFactory.createTitledBorder("My Score"));

    }

    /**
     * initialize labels to display color's score
     * 
     * @param score
     *            to be rendered
     */
    private void makeLabelsForColors(final Score score) {
        this.removeAll();
		Map<IngeniousColor, Integer> sm = score.getScoreMap();
		JTable t=new JTable(toTableModel(sm));
		this.add(t);
    }

	public static TableModel toTableModel(Map<?,?> map) {
		DefaultTableModel model = new DefaultTableModel(new Object[] { "Color", "Score" }, 0);
		for (Map.Entry<?,?> entry : map.entrySet()) {
			model.addRow(new Object[] { entry.getKey(), entry.getValue() });
		}
		return model;
	}

    /**
     * 
     * @param score
     *            socre to be rendered
     */
    public void update(final Score score) {
        makeLabelsForColors(score);
    }
}
